package com.ifacebox.face.track.ui;

import com.ifacebox.face.track.model.FacePage;

import javax.swing.*;

/**
 * @author znn
 */
public class FacePagePicker extends JComboBox<FacePage> {
    private static final FacePage[] PAGE_SIZES = new FacePage[]{new FacePage(10), new FacePage(20)
            , new FacePage(30), new FacePage(40), new FacePage(50)};

    public FacePagePicker() {
        super.setModel(new PagePickerModel(PAGE_SIZES));
        super.setSelectedItem(new FacePage(50));
    }

    public FacePage getSelectedPage() {
        return (FacePage) this.getSelectedItem();
    }


    static class PagePickerModel extends DefaultComboBoxModel<FacePage> {
        public PagePickerModel(FacePage[] facePage) {
            super(facePage);
        }

        @Override
        public FacePage getSelectedItem() {
            return (FacePage) super.getSelectedItem();
        }

        @Override
        public void setSelectedItem(Object facePage) {
            if (facePage instanceof FacePage) {
                super.setSelectedItem(facePage);
            }
        }
    }
}
